package main

import (
	"fmt"
	"gitee.com/yqs2009cl/gtt"
	"time"
)

func main() {
	gtt.On("test", on)
	gtt.On("test2", on)

	go func() {

		bus := gtt.On("test3", func(d gtt.Data) []byte {
			fmt.Println("test3")
			return nil
		})
		defer bus.Close()
		time.Sleep(time.Second * 5)
		return

	}()
	num := 0
	for {
		gtt.Emit("test", []byte("hello world"))
		time.Sleep(time.Second * 1)
		num++
		if num > 10 {
			num = 0
			rdata := gtt.Get("test2", []byte("hello world123"))
			fmt.Println(string(rdata))
		}
	}
	select {}
}
func on(d gtt.Data) []byte {
	fmt.Println(string(d.Data))
	return d.Data
}
